package com.in.ussd;

import java.util.List;

import android.os.Bundle;
import android.widget.TextView;

import com.in.ussd.constant.ConstantVariables;
import com.in.ussd.database.UssdDatasource;
import com.in.ussd.model.UssdAdapterModel;

public class UssdInformationActivity extends BaseActivity {

	private UssdDatasource database;
	private List<UssdAdapterModel> listUssds;
	private TextView txtSelectedInfo;
	private TextView txtCodeDetail;

	private Integer strSelectedId;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_ussd_information);

		// get screen parameters
		strSelectedId = getIntent().getIntExtra(
				ConstantVariables.EXTRA_USSD_ID, 0);

		// Set text
		txtSelectedInfo = (TextView) findViewById(R.id.txtSelectedInfo);

		txtCodeDetail = (TextView) findViewById(R.id.txtCodeDetail);

		database = new UssdDatasource(getApplicationContext());
		setupAdmob();
		share();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		database.open();
		initData();
	}

	private void initData() {

		listUssds = database.getUssdInformation(strSelectedId);

		if (listUssds.size() > 0) {
			UssdAdapterModel model = listUssds.get(0);

			txtSelectedInfo.setText(model.getUssdDetail().trim());
			txtCodeDetail.setText(model.getUssdCode().trim());
		}

	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		database.close();
	}
}
